# Contributor: Grigory Kirillov <txgk@bk.ru>
# Maintainer:
pkgname=palp
pkgver=2.20
pkgrel=1
pkgdesc="Package for Analyzing Lattice Polytopes"
url="http://hep.itp.tuwien.ac.at/~kreuzer/CY/CYpalp.html"
arch="all"
license="GPL-3.0-only"
options="!check" # no test suite
source="http://hep.itp.tuwien.ac.at/~kreuzer/CY/palp/palp-$pkgver.tar.gz"
_files="poly class cws nef mori"
_dimensions="4 5 6 11"

prepare() {
	default_prepare
	mkdir -p bin
	mv Global.h Global.h.template
}

build() {
	export CFLAGS="${CFLAGS/-Os/-O3}" # gotta go fast

	# Inspired by https://git.sagemath.org/sage.git/plain/build/pkgs/palp/spkg-install.in
	local dim file
	for dim in $_dimensions; do
		sed "s/^#define[^a-zA-Z]*POLY_Dmax.*/#define POLY_Dmax $dim/" Global.h.template > Global.h
		make
		for file in $_files; do
			mv "$file".x bin/"$file-${dim}d.x"
		done
	done
}

package() {
	local dim file
	for file in $_files; do
		for dim in $_dimensions; do
			install -Dm755 -t "$pkgdir"/usr/bin bin/"$file-${dim}d.x"
		done
		ln -sf "$file"-6d.x "$pkgdir"/usr/bin/"$file.x"
	done
}

sha512sums="
08d9a8543c2253297d6ff9076c7e27b9086dc758599f4a0a0348d391e583b3c9ccd9315cce6f425f62432d546a68e689def55c3a8c1f5a5e17bf7998468d1ee2  palp-2.20.tar.gz
"
